<?php
//include files for session timeout and DB connection
//include 'session.php';
include 'connect.php';

$ref = $_GET['ref'];
$type = $_GET['type'];
$page = $ref.'.php';

if (empty($_GET['realm'])||empty($_GET['char'])||empty($_GET['type']))
{
if (empty($_GET['ref']))
{header ('Location: index.php');}
else 
{
header ('Location: $page');
}
}

//start html head
echo "<html><head>";
//Load the AJAX API
echo "<script type='text/javascript' src='https://www.google.com/jsapi'></script>";
echo "<script type='text/javascript'>";
// Load the Visualization API and the piechart package.
echo      "google.load('visualization', '1.0', {'packages':['corechart']});";
// Set a callback to run when the Google Visualization API is loaded.
echo      "google.setOnLoadCallback(drawChart);";
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.

$realm = stripslashes(stripslashes($_GET['realm']));
$char = stripslashes(stripslashes($_GET['char']));

//fix case - convert to lowercase and initcaps
$realm = ucwords(strtolower($realm));
$char = ucwords(strtolower($char));

$_SESSION['realm']=$realm;
$_SESSION['char']=$char;

if ($type=='level')
{
$title = 'Level history';
$xAxis = 'Date';
$yAxis = 'Level';
$yAxisMax = 90;
$yAxisMin = 10;
//get level with corresponding date via query
$sql = mysqli_query($mysqli,"SELECT char_history.level, char_history.last_login, char_history.points, char_history.item_level FROM char_history INNER JOIN char_summary ON char_history.char_id = char_summary.char_id
WHERE char_summary.name like '$char' AND char_summary.realm like '$realm' order by char_history_id");

//count number of data points
$rowCount = mysqli_num_rows($sql);

//query column to graph
$dataX = 1;
$dataY = 0;
include 'graphobject.php';
}
else if ($type=='profession')
{
$title = 'Profession history';
$xAxis = 'Date';
$yAxis = 'Skill level';
$yAxisMax = 550;
$yAxisMin = 1;
//get profession level (expected level?)
$sql = mysqli_query($mysqli,"SELECT cp.pro_val, cp.pro_name, char_history.last_login FROM char_history INNER JOIN char_summary ON char_history.char_id = char_summary.char_id INNER JOIN char_history_pro cp ON char_history.char_history_id = cp.char_history_id
WHERE char_summary.name like '$char' AND char_summary.realm like '$realm' 
AND type='P'
order by char_history.char_history_id");

//count number of data points
$rowCount = mysqli_num_rows($sql);

//query column to graph
$dataX = 2;
$dataY = 0;
require 'graphobject.php';
}
else if ($type=='skill')
{

}
else if ($type=='ilevel')//item level
{

}

include 'footer.html';


?>